package com.slaffka.model;

import org.jboss.solder.core.Veto;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: slaffka
 * Date: 04.11.12
 * Time: 16:56
 * To change this template use File | Settings | File Templates.
 */
@Entity
@Table(name = "debtor",
        uniqueConstraints =
        @UniqueConstraint(name = "debtor_fio_unq", columnNames = {"lastname", "firstname", "middlename", "birthday"})
)
@Veto
public class Debtor implements Serializable {

    private Long debtorId;

    private String firstName;
    private String lastName;
    private String middleName;
    private Date birthday;
    private List<Passport> passportList;
    private String description;
    private String registerAddress;
    private String factAddress;
    private String phone;

    @Id
    @Column(name = "debtor_id")
    @GeneratedValue(strategy = GenerationType.AUTO)
    public Long getDebtorId() {
        return debtorId;
    }

    public void setDebtorId(Long debtorId) {
        this.debtorId = debtorId;
    }

    @Column(name = "firstname", nullable = false)
    public String getFirstName() {
        return firstName;
    }

    public void setFirstName(String firstName) {
        this.firstName = firstName;
    }

    @Column(name = "lastname", nullable = false)
    public String getLastName() {
        return lastName;
    }

    public void setLastName(String lastName) {
        this.lastName = lastName;
    }

    public String getMiddleName() {
        return middleName;
    }

    public void setMiddleName(String middleName) {
        this.middleName = middleName;
    }

    @Temporal(value = TemporalType.DATE)
    @Column(name = "birthday", nullable = false)
    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    @OneToMany(fetch = FetchType.LAZY, cascade = CascadeType.ALL)
    @JoinTable(
            name = "debtor_passport",
            joinColumns = @JoinColumn(name = "debtor_id"),
            inverseJoinColumns = @JoinColumn(name = "passport_id")
    )
    public List<Passport> getPassportList() {
        return passportList;
    }

    public void setPassportList(List<Passport> passportList) {
        this.passportList = passportList;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getRegisterAddress() {
        return registerAddress;
    }

    public void setRegisterAddress(String registerAddress) {
        this.registerAddress = registerAddress;
    }

    public String getFactAddress() {
        return factAddress;
    }

    public void setFactAddress(String factAddress) {
        this.factAddress = factAddress;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    @Transient
    public String getFIO(){
        return lastName + " " + firstName + " " + middleName;
    }
}
